﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;

namespace WCF_AutoUpdates_Services.WinService
{
    partial class WinahrimanAutoUpdate : ServiceBase
    {
        private ServiceHost wcfHost = null;

        public WinahrimanAutoUpdate()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                this.wcfHost = new ServiceHost(typeof(WCF_AutoUpdates_Services.WCFService.AutoUpdate));
                this.wcfHost.Open();
            }
            catch (Exception ex)
            {
                this.EventLog.WriteEntry(ex.Message, EventLogEntryType.Error);
                this.Stop();
            }
        }

        protected override void OnStop()
        {
            try
            {
                if (this.wcfHost != null && this.wcfHost.State != CommunicationState.Closed && this.wcfHost.State != CommunicationState.Faulted)
                {
                    this.wcfHost.Close();
                }
            }
            catch (Exception ex)
            {
                this.EventLog.WriteEntry(ex.Message, EventLogEntryType.Error);
            }
        }
    }
}
